/*
 * jinlanbao
 */
package com.jlb.zx.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baidu.fsg.uid.UidGenerator;
import com.jlb.core.base.BaseDAO;
import com.jlb.core.base.BaseSVImpl;
import com.jlb.core.entity.Page;
import com.jlb.core.exceptions.BaseException;
import com.jlb.zx.dao.ZxMemberDAO;
import com.jlb.zx.entity.ZxMember;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("zxMemberSV")
@Slf4j
public class ZxMemberSVImpl extends BaseSVImpl<ZxMember, Long> implements ZxMemberSV {

    @Autowired
    private ZxMemberDAO zxMemberDAO;

    @Resource
    private UidGenerator uidGenerator;

    @Override
    protected BaseDAO getBaseDAO() {
        return zxMemberDAO;
    }

    /**
     * 保存account对象
     *
     * @param entity 实体
     * @throws BaseException
     */
    @Override
    public void save(ZxMember entity) throws BaseException {
        super.save(entity);
    }


    /**
     * 查询ZxMember分页
     *
     * @param zxMember 对象
     * @param offset   查询开始行
     * @param limit    查询行数
     * @return List<ZxMember>
     */
    @Override
    public List<ZxMember> list(ZxMember zxMember, int offset, int limit) {
        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }

        Map<String, Object> map = null;
        if (zxMember != null) {
            map = JSON.parseObject(JSON.toJSONString(zxMember, SerializerFeature.WriteDateUseDateFormat));
        } else {
            map = new HashMap<>();
        }
        return zxMemberDAO.list(map, new RowBounds(offset, limit));
    }

    @Override
    public int count(ZxMember zxMember) {
        Map<String, Object> map = null;
        if (zxMember != null) {
            map = JSON.parseObject(JSON.toJSONString(zxMember, SerializerFeature.WriteDateUseDateFormat));
        } else {
            map = new HashMap<>();
        }
        return zxMemberDAO.count(map);
    }

    /**
     * 查询ZxMember分页
     *
     * @param offset 查询开始行
     * @param limit  查询行数
     * @return List<ZxMember>
     */
    @Override
    public List<ZxMember> list(int offset, int limit) {
        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }
        Map<String, Object> param = new HashMap<>();
        return zxMemberDAO.list(param, new RowBounds(offset, limit));
    }

    @Override
    public int count() {
        Map<String, Object> param = new HashMap<>();
        return zxMemberDAO.count(param);
    }

    @Override
    public List<ZxMember> listForCreateSql() {
        return zxMemberDAO.listForCreateSql();
    }

    @Override
    public ZxMember loadByUid(String uuid) {
        return zxMemberDAO.loadByUid(uuid);
    }

    @Override
    public ZxMember loadBonus(Map<String, Object> params) {
        return zxMemberDAO.loadBonus(params);
    }

}
